package com.lcy.web.base

import com.fasterxml.jackson.annotation.JsonInclude
import com.fasterxml.jackson.databind.ObjectMapper
import com.fasterxml.jackson.databind.SerializationFeature
import org.springframework.stereotype.Component
import java.text.SimpleDateFormat
import javax.ws.rs.ext.ContextResolver
import javax.ws.rs.ext.Provider

/**
 * 设置 json 数据中 date 的格式，过滤 json 中为空的字段
 * Created by loucunyin on 6/24/17.
 */
@Provider
@Component
open class JsonConfig : ContextResolver<ObjectMapper>{
    val mapper = ObjectMapper()
    init {
        mapper.configure(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS,false)
        mapper.dateFormat = SimpleDateFormat(BaseConst.DATE_TIME_FORMAT)
        mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL)
    }
    override fun getContext(type: Class<*>?): ObjectMapper {
        return mapper
    }

}